 <?php
	require_once('db_connect.php');
	require_once('distance.php');
	
	$location = $_GET['location']; // 창천동 등 지역명
	$lat = $_GET['lat'];
	$lng = $_GET['lng'];
	$radius = $_GET['radius'];
	
	$query = "select * from sale_events";
	$data = mysqli_query($conn, $query)
		or die('sale_events 가져오는 쿼리 실패');

	$sale_events = array();
	while ($row = mysqli_fetch_array($data)) {
//		array_push($sale_events, array('distance' => distance($lat, $lng, doubleval($row['lat']), doubleval($row['lng']))));
		
		if (distance($lat, $lng, doubleval($row['lat']), doubleval($row['lng'])) <= doubleval($radius)) {
			$a_sale_event = array('lat' => $row['lat'], 'lng' => $row['lng'], 'shop_name' => $row['shop_name'],
														'item' => $row['item'], 'event' => $row['event']);
			array_push($sale_events, $a_sale_event);
		}
	}
	mysqli_close($conn);
	echo json_encode($sale_events);
?>